//
//  TestDownloadProgress.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/20.
//

import SwiftUI

struct TestDownloadProgress: View {
  @State private var isLoading: Bool = false
  var body: some View {
    ZStack {
      Text("loading")
        .font(.system(size: 35, weight: .bold,design: .rounded))
        .offset(y: -40)
      RoundedRectangle(cornerRadius: 10)
      //fill
        .fill(Color(.systemGray5))
        .frame(width: 300, height: 10)

      // 进度条
      RoundedRectangle(cornerRadius: 10)
        .fill(.green)
        .frame(width: 50, height: 10)
        .animation(.linear(duration: 1.5).repeatForever(autoreverses: false), value: isLoading)
        .offset(x: isLoading ? 125 : -125)
        .onAppear() {
          isLoading = true
        }
    }
  }
}

#Preview {
  TestDownloadProgress()
}
